package com.scc.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.scc.entites.CategoriesEntity;
import com.scc.persistence.ICategorySetupDAO;

@Service
public class CategoriesSetupService implements ICategoriesSetupService
{
   @Autowired
   ICategorySetupDAO categSetupDAO;

   @Transactional
   public void createCategory(String code, String name)
   {
      CategoriesEntity categ = new CategoriesEntity(code, name);
      categSetupDAO.createCategory(categ);
   }

   @Transactional(readOnly=true)
   public CategoriesEntity getCategory(String code)
   {
      CategoriesEntity category = categSetupDAO.getCategory(code);
      return category;
   }

   @Transactional(readOnly=true)
   public List<CategoriesEntity> getAll()
   {
      List<CategoriesEntity> result = categSetupDAO.getAll();
      return result;
   }

   @Transactional
   public void updateCategory(String code, String name)
   {
      CategoriesEntity fromDB = categSetupDAO.getCategory(code);
      fromDB.setName(name);
      categSetupDAO.updateCategory(fromDB);
   }

   @Transactional
   public void deleteCategory(String code)
   {
      CategoriesEntity fromDB = categSetupDAO.getCategory(code);
      categSetupDAO.deleteCategory(fromDB);
   }
   
   public void setCategSetupDAO(ICategorySetupDAO categSetupDAO)
   {
      this.categSetupDAO = categSetupDAO;
   }
}